package cn.itcast.tags.meta
import org.apache.spark.sql.Column


/**
 *
	inType=json
	inPath=datas/json
	selectFieldNames=name
 */
case class JsonMeta(
                     inPath: String,
                     sperator: String,
                     selectFieldNames: Array[Column]
                   )

object JsonMeta{

  /**
   *
   * @param ruleMap map集合
   * @return
   */
  def getJsonMeta(ruleMap: Map[String, String]): JsonMeta = {

    // 将选择字段构建为Column对象
    import org.apache.spark.sql.functions.col
    val fieldColumns: Array[Column] = ruleMap("selectFieldNames")
      .split(ruleMap("sperator"))
      .map{field => col(field)}

    // 创建HdfsMeta对象并返回
    JsonMeta(
      ruleMap("inPath"), //
      ruleMap("sperator"), //
      fieldColumns
    )
  }
}